package org.jeecg.modules.rental.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.jeecg.modules.rental.entity.RentalCouponWriteoff;
import org.jeecg.modules.rental.mapper.RentalCouponWriteoffMapper;
import org.jeecg.modules.rental.service.IRentalCouponWriteoffService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: 卡券核销
 * @Author: sean
 * @Date:   2024-08-19
 * @Version: V1.0
 */
@Service
@RequiredArgsConstructor
public class RentalCouponWriteoffServiceImpl extends ServiceImpl<RentalCouponWriteoffMapper, RentalCouponWriteoff> implements IRentalCouponWriteoffService {

//    private final RentalAccountCouponMapper rentalAccountCouponMapper;

//    private final RentalStoreMapper rentalStoreMapper;

    @Override
    public IPage<RentalCouponWriteoff> selectJoinPage(Page page, RentalCouponWriteoff entity) {
        IPage<RentalCouponWriteoff> pageList = baseMapper.selectJoinPage(page, entity);
        if(ObjectUtil.isNotEmpty(pageList)){
            List<Long> accountCouponIds = pageList.getRecords().stream().map(RentalCouponWriteoff::getAccountCouponId).collect(Collectors.toList());
//            List<RentalAccountCoupon> accountCouponList = rentalAccountCouponMapper.selectBatchIds(accountCouponIds);
            List<Long> storeIds = pageList.getRecords().stream().map(RentalCouponWriteoff::getStoreId).collect(Collectors.toList());
//            List<RentalStore> storeList = rentalStoreMapper.selectBatchIds(storeIds);
            pageList.getRecords().stream().forEach(item->{
//                RentalAccountCoupon accountCoupon = accountCouponList.stream()
//                        .filter(a-> a.getId().equals(item.getAccountCouponId())).findFirst().orElse(null);
//                if(ObjectUtil.isNotEmpty(accountCoupon)){
//                    item.setConfigName(accountCoupon.getConfigName());
//                    item.setFaceValue(accountCoupon.getFaceValue());
//                    item.setMinAmount(accountCoupon.getMinAmount());
//                    item.setCouponCode(accountCoupon.getCouponCode());
//                }
//                RentalStore store = storeList.stream()
//                        .filter(a-> a.getId().equals(item.getStoreId())).findFirst().orElse(null);
//                if(ObjectUtil.isNotEmpty(store)){
//                    item.setStoreName(store.getMeshPointsName());
//                }
            });
        }
        return pageList;
    }
}
